<?php

namespace App\Http\Middleware;

use App\models\Order;
use Closure;
use Illuminate\Support\Facades\View;

class OrderMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //       未付款的订单数据
        $worder = Order::where('user_id',auth()->id())->where('status','未付款')->get();
        $yorder = Order::where('user_id',auth()->id())->where('status','已付款')->get();
        $dorder = Order::where('user_id',auth()->id())->where('status','已发货')->get();
        $corder = Order::where('user_id',auth()->id())->where('status','已完成')->get();
//        向视图分配数据
        View::share('worder',$worder);
        View::share('yorder',$yorder);
        View::share('dorder',$dorder);
        View::share('corder',$corder);
        return $next($request);
    }
}
